import request from '../../utils/request.js'
import Vue from 'vue'
const state = {
	cartList: []
}
const getters = {}
const mutations = {
	addCartListMutation({cartList},payload){
		// 从商品详情页将一个商品对象全部传过来,
		// 如果cartList中存在,则直接覆盖 count,selected属性
		const existItem = cartList.find(item=>item.id === payload.id)
		if(existItem){
			existItem.count++
		}else{
			//如果cartList中 不存在,则添加到cartList中,注意count,selected一开始不存在
			Vue.set(cartList,'selected',true)
			Vue.set(cartList,'count',1)
			cartList.push(payload)
		}
		
	}
}
const actions = {

}
export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
